package cn.wmlce.service;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;

import javax.ejb.Schedule;

/**
 * 1:在PushService里产生DeferredResult给控制器使用，通过Scheduled注解定时更新DeferredResult
 */
@Service
public class PushService {

    private DeferredResult<String> deferredResult;//1

    public DeferredResult<String> getAsyncUpdate(){//1
        deferredResult = new DeferredResult<String>();
        return deferredResult;
    }

    @Scheduled(fixedDelay = 5000)
    public void refresh(){
        if(deferredResult != null){
            deferredResult.setResult(new Long(System.currentTimeMillis()).toString());
        }
    }
}
